 export const selectData1 = async (jybh,obj,jylb) => {
    const res = await window.xinpuHttpApi(jybh,obj,jylb);
    return res;
}

//1查询数据源的变量常量
export var dataSourceWeb1 = ref([]); 
export const selectDataWeb1 = async (jybh,obj) => {
    const res = await window.xinpuWebsApi(jybh, obj);
    dataSourceWeb1.value=res.ReContent;
    return res;
}
//2保存交易
export const saveData1=async(jybh,jylb,dataSource,sycxlb)=>{
    let dataSourceTableListConst = {"sycxlb":"","list":[]}  //临时数据源用来存储插入、修改、删除数据源 
    console.log(dataSource)
    for(let i=0;i<dataSource.length;i++){
      if(dataSource[i].saveflag!=0 && dataSource[i].saveFlag!=0){
         //移除这两个属性
        delete dataSource[i].ReContent;
        delete dataSource[i]._X_ROW_KEY;
        dataSourceTableListConst.list.push(dataSource[i]);  
      }
    }
    dataSourceTableListConst.sycxlb=sycxlb;
    const res = await window.xinpuHttpApi(jybh, dataSourceTableListConst,jylb);
    return res;
}

export const insertFun2=async (obj,dataSource,tableName)=>{
  //点插入的时候新建一行临时数据，数据里面给定一些默认值，其他让用户选择
  const insertRowObj=ref(obj);
  const $table = tableName.value;
  dataSource.push(insertRowObj.value);
  $table.setCurrentRow(insertRowObj);
  return '新建行成功';
}
//4.修改方法
//2.4修改方法
export const updateFun=(row,a,dataSource,tableName,updateConst,obj)=>{
   
  const $table = tableName.value;
  if(a==1){
    updateConst=row.column.model.value;
    console.log(updateConst);
  }
  else if(a==2){
       
      if(dataSource[$table.getRowSeq(obj.value)-1].saveflag==0){
        if(updateConst!=row.column.model.value){
          dataSource[$table.getRowSeq(row.row)-1].saveflag=2;
          //  判断成功后，就把updateConst恢复为空
          updateConst='';
        }
      }
      else if(dataSource[$table.getRowSeq(obj.value)-1].saveFlag==0){
        if(updateConst!=row.column.model.value){
          dataSource[$table.getRowSeq(row.row)-1].saveFlag=2;
          //  判断成功后，就把updateConst恢复为空
          updateConst='';
        }
      }
  } 
  else if(a==3){
    cellClick(row,obj );
  }
}
export const cellClick=(row ,obj)=>{
  obj.value=row.row;
}
//2.3删除方法
export const deleteFun=(dataSource,tableName)=>{
   
    const $table = tableName.value;
    
    //获取高亮行
    const selectRecords = $table.getCurrentRecord();
   
    if(dataSource[$table.getRowSeq(selectRecords)-1].saveflag==0){
       
      dataSource[$table.getRowSeq(selectRecords)-1].saveflag=3;
    }
    else if(dataSource[$table.getRowSeq(selectRecords)-1].saveFlag==0){
       
      dataSource[$table.getRowSeq(selectRecords)-1].saveFlag=3;
    }  
}

//deleteFun2费用小类界面项目打包子界面删除的时候需要提供该行的唯一标识(项目编号bh)
export const deleteFun2=(dataSource,tableName,bh)=>{
  const $table = tableName.value;
  //获取高亮行
  const selectRecords = $table.getCurrentRecord();
 
  if(dataSource[$table.getRowSeq(selectRecords)-1].saveflag==0){
     
    dataSource[$table.getRowSeq(selectRecords)-1].saveflag=3;
    dataSource[$table.getRowSeq(selectRecords)-1].bh=bh;
  }
  else if(dataSource[$table.getRowSeq(selectRecords)-1].saveFlag==0){
    console.log(bh)
    dataSource[$table.getRowSeq(selectRecords)-1].saveFlag=3;
    dataSource[$table.getRowSeq(selectRecords)-1].bh=bh;
  }  
}

export const biaoshi = (cellValue ) => {
  if(cellValue=='2')
  {
   return   '待改'
  }
  else if(cellValue=='1')
  {
   return  '待增'
  }
  else if(cellValue=='3')
  {
   return  '待删'
  }
  else if(cellValue=='9')
  {
   return  '待删'
  }
  else
  {
   return ''
  }  
}